to run Jupyter

jupyter notebook

In [2]:
print("Hello World!")


Hello World!

Variables


In [18]:
x=8

In [19]:
type(x)


Out[19]:
int

In [20]:
x.bit_length()


Out[20]:
4

In [21]:
x=3.14159

In [22]:
type(x)


Out[22]:
float

In [23]:
x=0.25

In [24]:
x.as_integer_ratio()


Out[24]:
(1, 4)

In [25]:
x="text"

In [26]:
x='text'

In [30]:
x="""
"Hello"
"""

In [32]:
x


Out[32]:
'\n"Hello"\n'

Tuple


In [33]:
x=(2,3,4,"text")

In [34]:
x[0]


Out[34]:
2

In [35]:
x[1]


Out[35]:
3

In [36]:
x[3]


Out[36]:
'text'

In [37]:
x[-1]


Out[37]:
'text'

In [38]:
x[-2]


Out[38]:
4

List


In [39]:
x=[2,4,6]

In [40]:
x.append(8)

In [41]:
x


Out[41]:
[2, 4, 6, 8]

In [42]:
x.pop()


Out[42]:
8

In [43]:
x


Out[43]:
[2, 4, 6]

In [44]:
x.pop(0)


Out[44]:
2

In [45]:
x


Out[45]:
[4, 6]

Dictionary


In [49]:
x={"key":"value", "cat":"a samll animal"}

In [50]:
x


Out[50]:
{'cat': 'a samll animal', 'key': 'value'}

In [51]:
x['cat']


Out[51]:
'a samll animal'

In [53]:
x['dog']="a larger animal"

In [54]:
x


Out[54]:
{'cat': 'a samll animal', 'dog': 'a larger animal', 'key': 'value'}

In [56]:
x.get("duck", "not found")


Out[56]:
'not found'

for loop


In [57]:
for i in [2,4,6,8]:
    print(i)


2
4
6
8

In [62]:
for i in range(2,11,2):
    print(i)


2
4
6
8
10

While loop


In [66]:
i=0
while i<4:
    print(i)
    i+=1


0
1
2
3

function


In [69]:
def f(x):
    return x*x

In [70]:
f(3)


Out[70]:
9

In [71]:
g=f

In [72]:
g(5)


Out[72]:
25

In [73]:
def h(x=0):
    y=2*x
    return y

In [74]:
h(3)


Out[74]:
6

In [75]:
h()


Out[75]:
0

Quiz


In [76]:
with open("fibo_input.txt","r") as fp:
    s=fp.read()

In [82]:
n=[]
for i in s.split():
    n.append(int(i))

In [83]:
n


Out[83]:
[2, 3, 10, 27, 48, 56, 75, 89, 92]

In [84]:
%%timeit -n1
with open("fibo_input.txt","r") as fp:
    s=fp.read()
n=[]
for i in s.split():
    n.append(int(i))


1 loop, best of 3: 188 µs per loop

Solution


In [109]:



1
2
55
196418
4807526976
225851433717
2111485077978050
1779979416004714189
7540113804746346429
1
2
55
196418
4807526976
225851433717
2111485077978050
1779979416004714189
7540113804746346429
1
2
55
196418
4807526976
225851433717
2111485077978050
1779979416004714189
7540113804746346429
1 loop, best of 3: 851 µs per loop